#include<bits/stdc++.h>
using namespace std;
int main(){
  freopen("good.in","r",stdin);
  freopen("good.out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int n,q,x=0; string s; cin>>n>>q>>s;
  if(max(n,q)<=1e4){
    while(q--){
      int l,r,a=0,b=0,w=0; cin>>l>>r,l--,r--;
      vector<bool> f(n+1);
      for(int i=l,c=0;i<=r;i++)
        a+=(c+=s[i]&1?1:-1)<0;
      for(int i=r,c=0;i>=l;i--)
        b+=(c+=s[i]&1?1:-1)<0;
      if(a>b){
        for(int i=l,c=0;i<=r;i++)
          if((c+=s[i]&1?1:-1)<0)f[i]=true,c=0,w++;
        for(int i=r,c=0;i>=l;i--)
          if((c+=(s[i]&1?1:-1)+f[i+1])<0)c=0,w++;
      }
      else{
        for(int i=r,c=0;i>=l;i--)
          if((c+=s[i]&1?1:-1)<0)f[i+1]=true,c=0,w++;
        for(int i=l,c=0;i<=r;i++)
          if((c+=(s[i]&1?1:-1)+f[i])<0)c=0,w++;
      }
      x^=w;
    }
    cout<<x<<endl;
    return 0;
  }
  return 0;
}